
function count(value: string) {

  if (!value) return 0
  const len = 0
  let t = 0
  const key = value.match(/\{\{(.+?)\}\}/g)
  const emoji = value.match(/\[(.+?)\]/g)
  let content = value.replace(/\{\{(.+?)\}\}/g, '')
  if (emoji) {
    content = content.replace(/\[(.+?)\]/g, '')
  }


  for (let a = content.length, n = -1, r = 0; r < a; r++) {
    n = content.charCodeAt(r)
    t += n >= 0 && n <= 128 ? 0.5 : 1
  }
  // 计算动态词包长度
  if (key && key.length) {
    key.forEach((item: any) => {
      switch (item) {
        case '{{city}}':
          t += 4
          break
        case '{{gender}}':
          t += 2
          break
        case '{{day}}':
          t += 6
          break
        case '{{week}}':
          t += 3
          break
      }
    })
  }
  if (emoji) {
    t += emoji.length
  }
  return len + Math.ceil(t)
};

export { count }

